#include "vector.h"


namespace rt
{

Vector::Vector()
    :Array()
{
}

Vector::Vector(double a, double b, double c)
    :Array(a,b,c)
{
}

Vector::Vector(Point A, Point B)
{
    d[0] = B.data(0)-A.data(0);
    d[1] = B.data(1)-A.data(1);
    d[2] = B.data(2)-A.data(2);
    d[3] = B.data(3)-A.data(3);
}


void Vector::normalize()
{
    double n = this->norm();
    d[0] = d[0]/n;
    d[1] = d[1]/n;
    d[2] = d[2]/n;
}

double Vector::norm()
{
    return sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]) ;
}


double Vector::norm2()
{
    return d[0]*d[0]+d[1]*d[1]+d[2]*d[2] ;
}

Vector Vector::operator^(const Vector &a)
{
    return Vector(d[1]*a.d[2]-d[2]*a.d[1],
                  d[2]*a.d[0]-d[0]*a.d[2],
                  d[0]*a.d[1]-d[1]*a.d[0]);

}

double Vector::operator*(const Vector &a)
{
    return sqrt(d[0]*a.d[0]+d[1]*a.d[1]+d[2]*a.d[2]);
}


Vector Vector::operator*(const double &a_mul)
{
    return Vector(d[0]*a_mul,d[1]*a_mul,d[2]*a_mul);
}

Vector Vector::operator+(const Vector &a_vector)
{
    return Vector(d[0]+a_vector.d[0],
                  d[1]+a_vector.d[1],
                  d[2]+a_vector.d[2]);
}

}

